/*	This program produces Figure C.1 */

***** Set directories 
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/mainsample_medbcw.dta", clear

global listcontrols = " i.t i.ciiu2_1stobs i.ndep_cat_1stobs i.ndep_cat i.year#i.i.ciiu2_1stobs i.year#i.ndep_cat_1stobs "  
global listcontrolstransition = " i.t i.t#transition i.ndep_cat_1stobs i.ndep_cat_1stobs#i.transition i.ciiu2_1stobs i.ciiu2_1stobs#i.transition i.ndep_cat i.ndep_cat#i.transition i.year#i.ciiu2_1stobs i.year#i.ciiu2_1stobs#i.transition i.year#i.ndep_cat_1stobs i.year#i.ndep_cat_1stobs#i.transition "


*** GRAPH COMPARING EFFECTS ACROSS SAMPLES, SELF-EMPLOYED
** Self-Employed (all) **
estimates clear
preserve
keep if self_empl==1 
sum W if time_bcw==-1
local meanw=r(mean)
g Wz=W/`meanw'		
eststo A: reghdfe Wz pre6 pre25 post03 post4, absorb(${listcontrols}) vce(cluster i ) // semi-parametric
restore
** Self-employed (reports>min) **
preserve
keep if  self_empl==1 & ficto_1stobs==0 
sum W if time_bcw==-1
local meanw=r(mean)
g Wz=W/`meanw'		
eststo B: reghdfe Wz pre6 pre25 post03 post4, absorb(${listcontrols}) vce(cluster i ) // semi-parametric
restore
** Self-Employed (high attachment) **
preserve
keep if  self_empl==1 & prop_mself_empl>=0.7 
sum W if time_bcw==-1
local meanw=r(mean)
g Wz=W/`meanw'		
eststo C: reghdfe Wz pre6 pre25 post03 post4, absorb(${listcontrols}) vce(cluster i ) // semi-parametric
restore
** Self-Employed (two-pillar cohorts) **
preserve
keep if  self_empl==1  
sum W if time_bcw==-1 & transition==0
local meanw=r(mean)
g Wz=W/`meanw'
sum W if time_bcw==-1 & transition==1
local meanw=r(mean)
replace Wz=W/`meanw' if transition==1
eststo D: reghdfe Wz pre6 pre25 post03 post4 pre6_transition pre25_transition post03_transition post4_transition , absorb(${listcontrolstransition}) vce(cluster i )
restore
 **PLOT
label var pre25 	"2-5 Pre BCW" 
label var post03 	"0-3 Post BCW" 
label var post4 	"4+ Post BCW" 
coefplot (A, label(Full Sample) msymbol(O)) ///
	(B, label(Above Min. Contr. Base) msymbol(D)) ///
	(C, label(Frequent Reporters) msymbol(T)) ///
	(D, label(Two-Pillar Cohorts) msymbol(S)) ///
	, bylabel(Self-Employed) ///
  ||, keep(*:pre25 post03 post4) xline(0)  ///
ciopts(recast(rcap)) levels(90 95) scheme(s2color) graphregion(color(white)) legend(pos(2) ring(0) col(1))  
graph export "`dir_output'/figureC1.png",  replace 	
 

clear all
exit
